window.Dareng = window.Dareng || {};
window.Dareng.base = window.Dareng.base || {}; (function($) {
    var topDomain = document.domain;
    var base = {
        init: function() {
            var _this = this;
            $(window).scroll(function() {
                if ($(window).scrollTop() > 30) {
                    $("#top-header").addClass("fixedNav hui-fadeinT");
                } else {
                    $("#top-header").removeClass("fixedNav hui-fadeinT");
                }
            });
            _this.initEvent();
			_this.promoText();
        },
        initEvent:function(){
            var _this = this;
        },
		promoText: function() {
			var clipboard, textTipsIndex,data_id;
			clipboard = new Clipboard('.promoText', {
				target: function() {
					return document.getElementById('copy-input');
				}
			});
			var ss=0;
			clipboard.on('success', function(e) {
				if(ss==0){
					ss=1;
					ding= parseInt($('#ding_'+data_id).html())+parseInt(1);
					$.ajax({
						type: "GET",
						url: SITEURL+"plugin.php?mod=tggoods&act=index&do=ding",
						data: {id:data_id},
						dataType: "json",
						async:false,
						success: function(data){
							ss=0;
							$('#ding_'+data_id).html(ding);
							
						}
					});
				}
				return layer.msg('恭喜，复制成功！', {icon: 1});
			});
			clipboard.on('error', function(e) {
				return layer.msg('您的浏览器不支持一键复制，请升级浏览器或更换浏览器', {icon: 2});
			});
			textTipsIndex = null;
			var s=0;
			$('.promoText').mouseenter(function() {
				var html, imgSrc, t, txt;
				if($(this).attr('data-s')==1) {
					t = '获取推广';
				} else {
					t = '复制推广';
				}
				$(this).text(t);
				txt = $(this).attr('data-text');
				txt = txt.replace(/\n/ig, "<br/>");
				data_id= $(this).attr('data-id');
				if(s==0){
					s=1;
					$.ajax({
						type: "POST",
						url: SITEURL+"plugin.php?mod=tggoods&act=index&do=img_data",
						data: {id:data_id},
						dataType: "json",
						async:false,
						success: function(data){
							//	imgSrc =$(this).attr('data-img');
							imgSrc=data.local_img;
							s=0;
						}
					});
				}
				
				html = "<div id='copy-input' style='width:1px;height:1px;overflow:hidden'><img style='width:290px;height:290px;' src='" + imgSrc + "'><br/>" + txt + "</div>";
				textTipsIndex = layer.tips(txt, this, {
					time: 0,
					area: ['500px']
				});
				$('#copy-input').remove();
				return $('body').append(html);
			});
			$('.promoText').mouseleave(function() {
				layer.close(textTipsIndex);
				if($(this).attr('data-s')==1) {
					t = '复制推广';
				} else {
					t = '获取推广';
				}
				return $(this).text(t);
			});
        },
    };
    window.Dareng.base = base;
    window.Dareng.base.init();
})(jQuery);